import javapns.Push;
import javapns.notification.PushNotificationPayload;
import javapns.notification.PushedNotifications;
import lombok.extern.slf4j.Slf4j;

import java.util.LinkedList;
import java.util.List;

/**
 * @ClassName: IosPush
 * @Author: 半仙
 * @Date: 2019/7/31 17:09
 * @Description :
 */
@Slf4j
public class IosPush2 {
    public static void main(String[] args) throws Exception {

        String keystore = "G:\\myEmpty\\demo\\src\\main\\resources\\dipingjie.p12";
        String password = "dipingjieTP";
        String deviceToken = "D21B76E8B893125A36A931535A3ACDAFC828748DAB86B47B3F022D370DCC7AEF"; //手机设备token号
        PushNotificationPayload payload = new PushNotificationPayload();
        payload.addBadge(1);//图标小红圈的数值
        // payload.addAlert("alert");
        payload.addCustomAlertBody("fuck me");//与上行 二留一
        //自定义k,v
        //payload.addCustomDictionary("url","http://shrenjun.com/#/page/news/c8a9740c-29fc-4126-ae6e-33ad4336a491/detail");
        payload.addCustomDictionary("url", "https://shrenjun.com/static/dist/index073102.html#/page/news/c8a9740c-29fc-4126-ae6e-33ad4336a491/detail");
        payload.addSound("default");//铃声
        //发送单条   .p12 证书,   密码   开发|生成环境 token
        //PushedNotifications result = Push.payload(payload, keystore, password, false, devicesToken);

        List<String> devices = new LinkedList<>();
        devices.add(deviceToken);
        //多线程群发  返回结果为集合对象
        PushedNotifications result = Push.payload(payload, keystore, password, false, 1, devices);
        //失败集合
        PushedNotifications failedNotifications = result.getFailedNotifications();
        System.out.println("失败数量:" + failedNotifications.size());
        //成功集合
        PushedNotifications successfulNotifications = result.getSuccessfulNotifications();
        System.out.println("成功数量:" + successfulNotifications.size());
        /**
         * 以上完成功能
         */
        //推送管理器
        /*PushNotificationManager pushManager = new PushNotificationManager();
        //初始化连接 true表示测试,false表示生产
        pushManager.initializeConnection(new AppleNotificationServerBasicImpl(
                keystore, password, true));
        //多条推送
        List<String> tokens = new ArrayList<>();
        tokens.add(deviceToken);
        List<Device> devicess = new ArrayList<>();
        for (String token : tokens) {
            devicess.add(new BasicDevice(token));
        }
        //发送通知 返回推送通知
        //PushedNotifications notifications = pushManager.sendNotifications(payload, devices);
        //发送通知 返回推送通知  多条
        List<PushedNotification> notifications = pushManager.sendNotifications(payload, devicess);

        //失败条目
        List<PushedNotification> failedNotification = PushedNotification
                .findFailedNotifications(notifications);
        //成功条目
        List<PushedNotification> successfulNotification = PushedNotification
                .findSuccessfulNotifications(notifications);
        //关闭连接
        log.info("失败:"+ failedNotification.size());
        log.info("成功:"+ successfulNotification.size());
        pushManager.stopConnection();
        log.info("发送完成");*/
    }
}
